5 * Split off from Article.php and Skin.php, 2003-12-22
14 var $mArticle, $mTitle, $mSkin;
15 var $lastline, $lastdate;
17 function PageHistory( $article ) {
18 $this->mArticle
=& $article;
19 $this->mTitle
=& $article->mTitle
;
22 # This shares a lot of issues (and code) with Recent Changes
25 global $wgUser, $wgOut, $wgLang;
27 # If page hasn't changed, client can cache this
29 if( $wgOut->checkLastModified( $this->mArticle
->getTimestamp() ) ){
30 # Client cache fresh and headers sent, nothing more to do.
33 $fname = 'PageHistory::history';
34 wfProfileIn( $fname );
36 $wgOut->setPageTitle( $this->mTitle
->getPRefixedText() );
37 $wgOut->setSubtitle( wfMsg( 'revhistory' ) );
38 $wgOut->setArticleFlag( false );
39 $wgOut->setArticleRelated( true );
40 $wgOut->setRobotpolicy( 'noindex,nofollow' );
42 if( $this->mTitle
->getArticleID() == 0 ) {
43 $wgOut->addHTML( wfMsg( 'nohistory' ) );
44 wfProfileOut( $fname );
48 list( $limit, $offset ) = wfCheckLimits();
50 /* We have to draw the latest revision from 'cur' */
52 $rawoffset = $offset - 1;
57 /* Check one extra row to see whether we need to show 'next' and diff links */
58 $limitplus = $rawlimit +
1;
60 $namespace = $this->mTitle
->getNamespace();
61 $title = $this->mTitle
->getText();
63 $db =& wfGetDB( DB_SLAVE
);
64 $use_index = $db->useIndexClause( 'articleid_timestamp' );
65 $oldtable = $db->tableName( 'old' );
67 $sql = "SELECT old_id,old_user," .
68 "old_comment,old_user_text,old_timestamp,old_minor_edit ".
69 "FROM $oldtable $use_index " .
70 "WHERE old_articleid='" . $db->strencode( $this->mTitle
->getArticleID() ) . "' " .
71 "ORDER BY inverse_timestamp".$db->limitResult($limitplus,$rawoffset);
72 $res = $db->query( $sql, $fname );
74 $revs = $db->numRows( $res );
76 if( $revs < $limitplus ) // the sql above tries to fetch one extra
77 $this->linesonpage
= $revs;
79 $this->linesonpage
= $revs - 1;
81 $atend = ($revs < $limitplus);
83 $this->mSkin
= $wgUser->getSkin();
84 $numbar = wfViewPrevNext(
86 $this->mTitle
->getPrefixedText(),
87 'action=history', $atend );
89 if($this->linesonpage
> 0) {
90 $submitpart1 = '<input class="historysubmit" type="submit" accesskey="'.wfMsg('accesskey-compareselectedversions').
91 '" title="'.wfMsg('tooltip-compareselectedversions').'" value="'.wfMsg('compareselectedversions').'"';
92 $this->submitbuttonhtml1
= $submitpart1 . ' />';
93 $this->submitbuttonhtml2
= $submitpart1 . ' id="historysubmit" />';
95 $s .= $this->beginHistoryList();
99 $s .= $this->historyLine(
100 $this->mArticle
->getTimestamp(),
101 $this->mArticle
->getUser(),
102 $this->mArticle
->getUserText(), $namespace,
103 $title, 0, $this->mArticle
->getComment(),
104 ( $this->mArticle
->getMinorEdit() > 0 ),
108 while ( $line = $db->fetchObject( $res ) ) {
109 $s .= $this->historyLine(
110 $line->old_timestamp
, $line->old_user
,
111 $line->old_user_text
, $namespace,
112 $title, $line->old_id
,
113 $line->old_comment
, ( $line->old_minor_edit
> 0 ),
117 $s .= $this->endHistoryList( !$atend );
119 $wgOut->addHTML( $s );
120 wfProfileOut( $fname );
123 function beginHistoryList() {
125 $this->lastdate
= $this->lastline
= '';
126 $s = '<p>' . wfMsg( 'histlegend' ) . '</p>';
127 $s .= '<form action="' . $wgTitle->escapeLocalURL( '-' ) . '" method="get">';
128 $prefixedkey = htmlspecialchars($wgTitle->getPrefixedDbKey());
129 $s .= "<input type='hidden' name='title' value='{$prefixedkey}' />\n";
130 $s .= !empty($this->submitbuttonhtml1
) ?
$this->submitbuttonhtml1
."\n":'';
131 $s .= '<ul id="pagehistory">';
135 function endHistoryList( $skip = false ) {
136 $last = wfMsg( 'last' );
138 $s = $skip ?
'' : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline
);
140 $s .= !empty($this->submitbuttonhtml2
) ?
$this->submitbuttonhtml2
: '';
145 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor, $counter = '' ) {
146 global $wgLang, $wgContLang;
148 $artname = Title
::makeName( $ns, $ttl );
149 $last = wfMsg( 'last' );
150 $cur = wfMsg( 'cur' );
151 $cr = wfMsg( 'currentrev' );
153 if ( $oid && $this->lastline
) {
154 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin
->makeKnownLink(
155 $artname, $last, "diff=\\1&oldid={$oid}",'' ,'' ,' tabindex="'.$counter.'"' ), $this->lastline
);
159 $dt = $wgLang->timeanddate( $ts, true );
166 $link = $this->mSkin
->makeKnownLink( $artname, $dt, $q );
169 $ul = $this->mSkin
->makeKnownLink( $wgContLang->specialPage( 'Contributions' ),
170 htmlspecialchars( $ut ), 'target=' . urlencode( $ut ) );
172 $ul = $this->mSkin
->makeLink( $wgContLang->getNsText(
173 Namespace::getUser() ) . ':'.$ut , htmlspecialchars( $ut ) );
178 $curlink = $this->mSkin
->makeKnownLink( $artname, $cur,
179 'diff=0&oldid='.$oid );
184 if( $this->linesonpage
> 1) {
185 # XXX: move title texts to javascript
188 $arbitrary = '<input type="radio" style="visibility:hidden" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'" />';
189 $checkmark = ' checked="checked"';
191 if( $counter == 2 ) $checkmark = ' checked="checked"';
192 $arbitrary = '<input type="radio" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'"'.$checkmark.' />';
195 $arbitrary .= '<input type="radio" name="diff" value="'.$oid.'" title="'.wfMsg('selectnewerversionfordiff').'"'.$checkmark.' />';
197 $s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary {$link} <span class='user'>{$ul}</span>";
198 $s .= $isminor ?
' <span class="minor">'.wfMsg( "minoreditletter" ).'</span>': '' ;
201 if ( '' != $c && '*' != $c ) {
202 $c = $this->mSkin
->formatcomment($c,$this->mTitle
);
203 $s .= " <em>($c)</em>";
207 $this->lastline
= $s;